package com.hqbzl.c1.rlock;

import lombok.extern.slf4j.Slf4j;

// 要求t2要在t1之后执行
@Slf4j
public class ThreadPattern {
    static final Object OBJECT = new Object();
    static boolean result = false;

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (OBJECT) {
                while (!result) {
                    try {
                        log.debug("wait t2 run");
                        OBJECT.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                log.debug("t1 run");
            }
        }, "t1").start();
        new Thread(() -> {
            synchronized (OBJECT) {
                log.debug("t2 run");
                result = true;
                OBJECT.notify();
            }
        }, "t2").start();
    }

}
